package com.google.fbyoutube.shared;

import java.util.HashMap;
import java.util.Map;


public class FBUtility {
	
	final static public String FB_ADDED = "fb_sig_added";
	final static public String FB_INFRAME = "fb_sig_in_iframe";
	final static public String FB_APIKEY = "fb_sig_api_key";
	final static public String FB_USERID = "fb_sig_user";
	final static public String FB_PROFILEUSERID = "fb_sig_profile_user";
	final static public String FB_PAGE_ID = "fb_sig_page_id";
	final static public String FB_SESSION = "fb_sig_session_key";
	final static public String FB_SSECRET = "fb_sig_ss";
	final static public String FB_APPID = "fb_sig_app_id";
	final static public String FB_LOGOUT = "fb_sig_logged_out_facebook";
	final static public String VIDEO_ID_PARAM = "vid";
	final static public String YT_USERNAME = "youtube_username";
	final static public String YT_USERPASSWORD = "youtube_password";
	final static public String YT_REGION = "region";

	final public static String FACEBOOK_APP_URL = "https://apps.facebook.com/";
	final public static String APP_NAME = "YouTube";
	final public static String THUMBNAIL_DEFAULT = "https://i.ytimg.com/1.jpg";
	
	final public static int BACKGROUND_FETCH_INTERVAL = 600000;	// 10 minutes
	
	final public static String API = "api";
	final public static String API_READ = "api_read";
	final public static String GRAPH = "graph";
	final public static String WWW = "www";
	final public static String SESSION = "session";
	
	final public static int CANVAS_WIDTH = 760;
	final public static int HOME_HEIGHT = 1300;
	final public static int WATCH_HEIGHT = 2200;
	final public static int FAV_HEIGHT = 1500;
	final public static int INVITE_HEIGHT = 800;
	final public static int FRIDFAV_HEIGHT = 1500;
	final public static int CONNECT_HEIGHT = 1600;
	
	final public static Map<String, String> DOMAIN_MAP = new HashMap<String, String> (4); 
	
	static {
		DOMAIN_MAP.put(API, "https://api.facebook.com/");
		DOMAIN_MAP.put(API_READ, "https://api-read.facebook.com");
		DOMAIN_MAP.put(GRAPH, "https://graph.facebook.com/");
		DOMAIN_MAP.put(WWW, "https://www.facebook.com/");
	}
	
	// Youtube on facebook
	final public static String APP_CALLBACK_URL = "https://youtubeonfb.appspot.com/";
	final public static String APP_URL = FACEBOOK_APP_URL + "youtubeonfb/";
	final public static String API_SECRET = "7d140ffcaa4c5a07c194610320a84930";
	final public static String APPID = "140444622729093";
	
	// Debug app
//	final public static String APP_CALLBACK_URL = "https://agiftcteator.appspot.com/";
//	final public static String APP_URL = FACEBOOK_APP_URL + "aipwehfipewh/";
//	final public static String API_SECRET = "f3e4d5434d9dcef47d7406b7ffc58829";
//	final public static String APPID = "134311373339861	";
	
	public static boolean debug() {
		return true;
	}
	
	public static String getVideoUrl(String vodID) {
		// append "&/" for fb:like, website is inaccessible error;
		String url = FBUtility.APP_URL + "?" + FBUtility.VIDEO_ID_PARAM + "=" + vodID + "&/";
		return url;
	}
	
	public static String getCbVideoUrl(String vodID) {
		// append "&/" for fb:like, website is inaccessible error;
		String url = FBUtility.APP_CALLBACK_URL + "?" + FBUtility.VIDEO_ID_PARAM + "=" + vodID ;
		return url;
	}
	
	public static String formatStr(String str) {
		if (str == null || str.equals(""))
			return "";
		java.lang.StringBuffer buf = new java.lang.StringBuffer(str.length() + 6);
		char ch = ' ';
		for (int i = 0; i < str.length(); i++) {
			ch = str.charAt(i);
			switch (ch) {
			case '<':
				buf.append("&lt;");
				break;
			case '>':
				buf.append("&gt;");
				break;
			case ' ':
				buf.append("&nbsp;");
				break;
			case '\n':
				buf.append("<br>");
				break;
			case '\'':
				buf.append("&#039;");
				break;
			case '"':
				buf.append("&quot;");
				break;
			default:
				buf.append(ch);
			}
		}
		str = buf.toString();
		return str;
	}
	
}
